from django.conf import settings
from models import Release, Poll

def recent_releases(request):
    recent_releases = Release.objects.filter(project__is_inactive=False, 
                                      project__hide=False).order_by("-created")
    if len(recent_releases) > settings.SHOW_RECENT_RELEASES:
        recent_releases = recent_releases[:settings.SHOW_RECENT_RELEASES]
    # last project of the month
    last = Poll.objects.get_last()
    lastw = None
    if last:
        lastw = last.winners.order_by("?")
    return {"recent_releases":recent_releases, "last_potm":last,
            "last_potm_w":lastw}
